from abc import ABC, ABCMeta, abstractmethod
import requests

class ProxyWebs(object,metaclass = ABCMeta):
    ##获取代理IP的网站

    def __init__(self,url):
        self._url = url
        self._proxyList = []

    @property
    def url(self):
        return self._url

    @url.setter
    def url(self,url):
        self._url = url

    @abstractmethod
    def _get_web(self,url):
        ##得到网页
        requests.adapters.DEFAULT_RETRIES = 3   #设置重试次数
        try:
            resp = requests.get(url,timeout=3)
        except requests.Timeout:
            print("请求超时")
        
        return resp.content

    @abstractmethod
    def _parser(self):
        ##解析网页，得到代理列表
        pass

    @abstractmethod
    def refresh_daily_proxy(self):
        ##更新每日代理
        pass

    @abstractmethod
    def init_proxy_pool(self):
        ##初始化代理池，爬取前20页的代理
        pass

    @abstractmethod
    def save_proxies(self):
        ##将代理列表保存入数据库
        pass

